/**
 * Copyright(c) YCHS. 2018 ALL Rigthts Reserved
 */
package com.yckj.bountyunion.utils;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ResourceBundle;

import org.apache.log4j.Logger;

import com.alibaba.druid.pool.DruidDataSource;

/**
 * 德鲁伊连接池，获取数据库连接
 * Date:2018年8月13日
 * @author hao
 * @version 1.0
 */
public class DruidDBUtil {
	
	//日志对象
	  private static Logger logger = Logger.getLogger(DruidDBUtil.class);
	
	//连接池资源对象
	private static DruidDataSource   dataSource= null;
	
	static {
		//读取properties文件内容
		ResourceBundle rb = ResourceBundle.getBundle("jdbc");
		String username=rb.getString("username");
		String password = rb.getString("password");
		String maxActive = rb.getString("maxActive");
		String maxWait = rb.getString("maxWait");
		String maxIdle = rb.getString("maxIdle");
		String url = rb.getString("jdbcUrl");
		String driverClassName = rb.getString("driverClassName");

		dataSource = new DruidDataSource();
		dataSource.setUsername(username);
		dataSource.setPassword(password);
		dataSource.setMaxActive(Integer.parseInt(maxActive));
		dataSource.setMaxWait(Integer.parseInt(maxWait));
		dataSource.setMinIdle(Integer.parseInt(maxIdle));
		dataSource.setUrl(url);
		dataSource.setDriverClassName(driverClassName);
		
	}
	 //获取连接的静态方法
	public static Connection getConnect() {
		
		Connection connection = null;
		try {
			connection = dataSource.getConnection();
		} catch (SQLException e) {
			logger.error("获取数据库连接失败!");
			e.printStackTrace();
		}
		return connection;
		
		
		
	}

}
